<template>
	<view @click="goApply" class="list-cell" style="padding: 6rpx 16rpx;border-bottom: 1rpx solid #f3f3f3;">
		<image :src="data.from_avatar" style="width: 80rpx;height: 80rpx;border-radius: 8rpx;" mode=""></image>
		<view class="info-view">
			<view style="width: 100%;display: flex;align-items: center;justify-content: space-between;">
				<view class="">
					{{data.from_name}}
				</view>
				<view class="statuscss" :style="{color:(data.status== 0 ? 'green' : '#666')}">
					{{getStatusInfo(data.status)}}
				</view>
			</view>
			<view
				style="font-size: 26rpx;color: #666;width: 100%;display: flex;align-items: center;justify-content: space-between;">
				<view class="">
					{{data.message}}
				</view>
				<view style="padding-right: 16rpx;color:#666;font-size: 28rpx;">
					<image src="/static/images/icon_left_top.png" style="width: 40rpx;height: 40rpx;" mode=""></image>
				</view>
			</view>
		</view>
		<u-action-sheet @click="click" :list="list" v-model="show"></u-action-sheet>
	</view>

</template>

<script>
	export default {
		name: "userapplyitem",
		data() {
			return {
				list: [{
					text: '通过申请',
				}, {
					text: '拒绝申请'
				}],
				show: false
			}
		},
		props: {
			data: {
				type: Object,
				default: () => {
					return {}
				}
			},
			changeApply: {
				type: Function
			}
		},
		methods: {
			click: async function(e) {
				console.log(e)
				const ret = await this.$u.post(`/user/user/changeApplyStatus`, {
					status: (e + 1),
					id: this.data.id
				})
				if (ret.success) {
					this.changeApply(this.data.id, e + 1)
					this.$store.dispatch({
						type: "address/refreshApply",
						payload: {}
					})
					if (e == 0) {
						this.$store.dispatch({
							type: "address/refreshFriends",
							payload: {}
						})
						this.$store.dispatch(`chats/init`, {})
					}
				} else {
					uni.showToast({
						title: ret.message ?? "请求失败",
						icon: "none"
					})
				}
			},
			goApply: function() {
				if (this.data.status == 0) {
					this.show = true
				}
			},
			getStatusInfo: function(status) {
				if (status == 0) {
					return "待验证"
				} else if (status == 1) {
					return "已添加"
				} else {
					return "已拒绝"
				}
			}
		}
	}
</script>

<style scoped>
	.statuscss {
		padding-right: 16rpx;
		color: #666;
		font-size: 28rpx;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		background: #f3f3f3;
		height: 100vh;
	}

	.list-cell {
		display: flex;
		box-sizing: border-box;
		width: 100%;
		padding: 0px 24rpx;
		overflow: hidden;
		color: #323233;
		font-size: 14px;
		line-height: 24px;
		background-color: #fff;
		align-items: center;
	}

	.name-view {
		margin-left: 16rpx;
		flex: 1;
		overflow: hidden;
		color: #323233;
		font-size: 14px;
		line-height: 24px;
		padding: 10px 0px;
	}

	.info-view {
		margin-left: 16rpx;
		flex: 1;
		overflow: hidden;
		color: #323233;
		font-size: 14px;
		line-height: 24px;
		padding: 1rpx 0px;
		display: flex;
		flex-direction: column;
	}
</style>